home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dnsconf / dnsping.c < prev    next >
C/C++ Source or Header  |  1996-08-03  |  3KB  |  88 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../misc/misc.h"
  5. #include "../misc/popen.h"
  6. #include "dnsconf.h"
  7. #include "../netconf/netconf.h"
  8. #include "dnsconf.m"
  9. #include "internal.h"
  10.  
  11. static DNSCONF_HELP_FILE help_dnsconnect ("connect");
  12.  
  13. /*
  14.     Do some test to see if the DNS is reachable or alive.
  15.     Return -1 if any error.
  16.  
  17.     This function should be used at configuration time
  18.     to avoid long timeout when no DNS is available.
  19. */
  20. int dns_ping ()
  21. {
  22.     int ret = 0;
  23.     if (dnsconf_isrslconf()){
  24.         if (dns_getserial("0.0.127.in-addr.arpa","",4)==-1) ret = -1;
  25.         if (!simul_ison()) net_prtlog ("%s: %s\n"
  26.             ,MSG_U(N_CHECKING,"Checking dns connectivity")
  27.             ,ret==-1 ? MSG_U(N_NOTGOOD,"Not good") : MSG_U(N_GOOD,"Ok"));
  28.         /* #Specification: dnsconf / dnsping / connectivity problem
  29.             linuxconf probe the DNS for proper setup. It does this by
  30.             sending a SOA request to the DNS with a timeout of 4 seconds.
  31.             If the request does not succeed, linuxconf print message
  32.             and ask the user if he wish to continue the network
  33.             operation he is doing (booting maybe). Unless he specify
  34.             NO, the operation will continue. This means that an
  35.             unattended boot will continue anyway even if the DNS is not
  36.             working properly. This won't be good but should make the
  37.             machine into some workable state.
  38.         */
  39.         if (ret == -1){
  40.             char errbuf[1000];
  41.             sprintf (errbuf,MSG_U(E_DNSPROBLEM
  42.                     ,"The DNS does not answer within %d seconds\n"
  43.                      "This is bad and will cause major problems later\n"
  44.                      "Do you want to continue ?\n"
  45.                      "\n"
  46.                      "(Note that this may indicate one minor DNS problem\n"
  47.                      " please consult the help screen for further info)"),4);
  48.             MENU_STATUS code = xconf_yesno (
  49.                 MSG_U(E_DNSCONNECT,"DNS connectivity")
  50.                 ,errbuf
  51.                 ,help_dnsconnect);
  52.             if (code == MENU_YES
  53.                 || (code == MENU_ESCAPE && dialog_mode != DIALOG_HTML)){
  54.                 ret = 0;
  55.             }
  56.         }
  57.     }
  58.     return ret;
  59. }
  60.  
  61. /*
  62.     Get the serial number of a domain
  63. */
  64. long dns_getserial (const char *domain, const char *server, int timeout)
  65. {
  66.     long ret = -1;
  67.     DAEMON *dae = daemon_find ("nslookup");
  68.     if (dae != NULL && dae->is_managed()){
  69.         char buf[500];
  70.         sprintf (buf,"%s -q=soa %s %s 2>/dev/null",dae->getpath()
  71.             ,domain,server);
  72.         POPEN p(buf);
  73.         while (ret == -1 && p.isok()){
  74.             if (p.wait(timeout)<=0) break;
  75.             while (p.readout(buf,sizeof(buf)-1)!=-1){
  76.                 char *pt = strstr(buf,"serial = ");
  77.                 if (pt != NULL){
  78.                     pt = str_skip (pt+9);
  79.                     ret = atol(pt);
  80.                     break;
  81.                 }
  82.             }
  83.         }
  84.     }
  85.     return ret;
  86. }
  87.  
  88.